package CreatThreadPool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class demo1 {
    public static void main(String[] args) {
        //使用工厂类获取线程池
        //1.0 获取固定的核心线程的线程池
        //创建一个核心线程只有3的线程池
        ExecutorService executorService = Executors.newFixedThreadPool(3);

        //2.0 获取可缓存的线程池
        ExecutorService executorService1 = Executors.newCachedThreadPool();

        //3.0 获取只有一个核心线程的线程池
        ExecutorService executorService2 = Executors.newSingleThreadExecutor();

        //4.0 获取固定线程的线程池，可定时执行任务
        ScheduledExecutorService executorService3 = Executors.newScheduledThreadPool(3);
        executorService3.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                System.out.println("Hello");
            }
        },1,3, TimeUnit.SECONDS);
    }
}
